Added keep alive setting - #41109
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new WSL Settings UI toggle to keep the WSL VM running indefinitely by driving the existing wsl2.vmIdleTimeout setting into a negative value (which the service interprets as “do not idle-terminate”).
Changes:
- Add a “Keep WSL VM alive” toggle to Optional Features, and disable the VM idle timeout expander when keep-alive is active.
- Extend the Optional Features view model with keep-alive/enablement properties and related change notifications.
- Add en-US localized strings (header/description and accessibility text) for the new setting.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml | Adds keep-alive toggle and disables the idle-timeout expander based on view model state. |
| src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs | Adds computed properties for keep-alive and VM idle-timeout enablement, and updates change notification flow. |
| localization/strings/en-US/Resources.resw | Adds localized strings for the new keep-alive setting and toggle accessibility metadata. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml:62
InstanceIdleTimeoutis used to implement “Keep WSL VM alive” by setting a negative timeout, but this header TextBlock formats the raw value viaMillisecondsStringConverter. With keep-alive enabled, this will display "-1 milliseconds" (and similarly for other negative values), which is user-unfriendly and doesn’t reflect the toggle semantics.
<ctControls:SettingsExpander x:Name="InstanceIdleTimeoutExpander" x:Uid="Settings_InstanceIdleTimeout" IsEnabled="{x:Bind ViewModel.InstanceIdleTimeoutEnabled, Mode=OneWay}">
<TextBlock Style="{StaticResource TextBlockSettingStyle}" Text="{x:Bind ViewModel.InstanceIdleTimeout, Mode=OneWay, Converter={StaticResource MillisecondsStringConverter}}"/>
# Conflicts: # localization/strings/en-US/Resources.resw
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs:93
- Toggling “Keep WSL VM alive” off always writes
_defaultInstanceIdleTimeoutback toInstanceIdleTimeout, which can discard a user’s previously configured distribution idle timeout (e.g., user sets 30000ms → enables keep-alive → disables keep-alive → value becomes default 15000ms). Consider preserving/restoring the last non-negative timeout value so the toggle doesn’t lose user configuration.
public bool IsOnKeepVMAlive
{
get { return _instanceIdleTimeout!.Int32Value < 0; }
set
{
Set(ref _instanceIdleTimeout!, value ? -1 : _defaultInstanceIdleTimeout, nameof(IsOnKeepVMAlive));
OnPropertyChanged(nameof(InstanceIdleTimeout));
OnPropertyChanged(nameof(InstanceIdleTimeoutEnabled));
OnPropertyChanged(nameof(VMIdleTimeoutEnabled));
InstanceIdleTimeout_ResetEnabled = !Equals(_defaultInstanceIdleTimeout, _instanceIdleTimeout!.Int32Value);
}
src/windows/wslsettings/Views/Settings/SettingsApplyHelper.cs:180
- Pending changes formatting will currently show negative idle timeouts as “-1 ms”. Since the service treats values < 0 as “never idle-terminate”, the apply dialog should format negative
InstanceIdleTimeout/VMIdleTimeoutas a user-friendly localized value (e.g. “Never”) instead of a negative duration.
case WslConfigEntry.InitialAutoProxyTimeout:
case WslConfigEntry.InstanceIdleTimeout:
case WslConfigEntry.VMIdleTimeout:
return string.Format("Settings_MillisecondsStringFormat".GetLocalized(), (int)value);
default:
benhillis
left a comment
There was a problem hiding this comment.
Nice, the mechanism checks out - _VmIsIdle() only returns true once no running instance has a valid client id, so pinning instanceIdleTimeout to a negative value does keep the VM up. A few things I hit while reading through it.
| </ctControls:SettingsExpander.Items> | ||
| </ctControls:SettingsExpander> | ||
| <ctControls:SettingsExpander x:Name="InstanceIdleTimeoutExpander" x:Uid="Settings_InstanceIdleTimeout" IsEnabled="{x:Bind ViewModel.InstanceIdleTimeoutEnabled, Mode=OneWay}"> | ||
| <TextBlock Style="{StaticResource TextBlockSettingStyle}" Text="{x:Bind ViewModel.InstanceIdleTimeout, Mode=OneWay, Converter={StaticResource MillisecondsStringConverter}}"/> |
There was a problem hiding this comment.
When the toggle is on, InstanceIdleTimeout is -1, and MillisecondsStringConverter only special-cases ulong 0, so this collapsed summary ends up reading literally -1 ms. Same thing shows up in the apply-changes dialog, since SettingsApplyHelper.FormatValue runs the new entry through Settings_MillisecondsStringFormat - so toggling Keep WSL VM alive produces a confirmation line like Distribution idle timeout: -1 ms for a field the user never touched.
Could we have the converter return null (or something like Never) for negative values, and map the toggle to Settings_KeepVMAlive/Header in the apply summary?
There was a problem hiding this comment.
I actually prefer it showing -1 as it is clearly communicating what it's setting. I think changing it to show 'Never' while making it more readable, makes it less clear on what actual settings are changing.
So I'd prefer to stick with displaying it as -1 as that is what gets truly set in the file.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/windows/wslsettings/Views/Settings/SettingsApplyHelper.cs:179
InstanceIdleTimeoutis formatted as milliseconds unconditionally. When the new "Keep WSL running" toggle sets this value to a negative number (e.g. -1), the Apply Changes dialog will display "-1 milliseconds", which is confusing for a user-facing setting that uses a sentinel value.
Consider special-casing negative InstanceIdleTimeout values to display a meaningful localized label (reusing the existing Keep WSL running header resource is one option) instead of formatting as milliseconds.
case WslConfigEntry.InitialAutoProxyTimeout:
case WslConfigEntry.InstanceIdleTimeout:
case WslConfigEntry.VMIdleTimeout:
return string.Format("Settings_MillisecondsStringFormat".GetLocalized(), (int)value);
Summary of the Pull Request
Added a setting to WSL settings to keep the WSL VM alive at all times.
PR Checklist
Very simple change.
Adds a 'InstanceIdleTimeout' setting and a "WSL keep VM alive" setting to WSL settings.
Detailed Description of the Pull Request / Additional comments
Did this in WSL settings only, no major code changes.
Validation Steps Performed
Validated settings loaded correctly.